//
//  AboutOus.m
//  takeout
//
//  Created by Mac on 12-6-24.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "AboutOus.h"

@implementation AboutOus
@synthesize aboutOusTableView;
@synthesize array;
- (void)viewDidLoad
{
    //手势
    UISwipeGestureRecognizer *recognizer; 
    recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
    [[self view] addGestureRecognizer:recognizer];

    //初始化背景图片
    UIImageView* bgView=[[UIImageView alloc] initWithFrame:CGRectMake(0,-6,320,465)];
    NSString *filePath=[[NSBundle mainBundle] pathForResource:@"aboutous" ofType:@"png"];
    [bgView setImage:[UIImage imageWithContentsOfFile:filePath]];
    [self.view addSubview:bgView];

    
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    // app名称
//    NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
    // app版本
    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    // app build版本
//    NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];
    NSString *version = [[NSString alloc]initWithFormat:@"          版本号：%@",app_Version];
    
    array = [[NSArray alloc] initWithObjects:@"              官方微博",version, nil];
    //用代码生成tableview并关联
    aboutOusTableView  = [[UITableView alloc] initWithFrame:CGRectMake(50, 250, 220, 100) style:UITableViewStyleGrouped];
	aboutOusTableView.dataSource = self;
	aboutOusTableView.delegate = self;
    [aboutOusTableView setBackgroundColor:[UIColor clearColor]];
    aboutOusTableView.backgroundView=nil;
    aboutOusTableView.scrollEnabled=NO;
	[self.view addSubview:aboutOusTableView];

    self.title=@"关于我们";
    //定义导航栏左侧按钮
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 54, 27)];
    NSString *filePath2=[[NSBundle mainBundle] pathForResource:@"navLeftBtn" ofType:@"png"];    
    [leftButton setBackgroundImage:[UIImage imageWithContentsOfFile:filePath2] forState:UIControlStateNormal];
    [leftButton setBackgroundImage:[UIImage imageWithContentsOfFile:filePath2] forState:UIControlStateHighlighted];
    [leftButton setTitle:@"返 回" forState:UIControlStateNormal]; 
    leftButton.titleLabel.font=[UIFont fontWithName:@"Helvetica-Bold" size:14]; 
    [leftButton addTarget:self action:@selector(backButtonPressd:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];

    self.navigationItem.leftBarButtonItem = leftItem;


}

-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{
    if(recognizer.direction==UISwipeGestureRecognizerDirectionRight) {
        [self.navigationController popViewControllerAnimated:YES];
        //执行程序
    }
}

- (void)backButtonPressd:(id)sender{
    NSURL *system_sound_url=[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"1248" ofType:@"wav"]];
    SystemSoundID system_sound_id;
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)system_sound_url, &system_sound_id);
    AudioServicesPlaySystemSound(system_sound_id);
    
    //将当前视图推出栈，程序将进入上一视图
    [self.navigationController popViewControllerAnimated:YES];
}
//设置cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 40;
}

//设置为2个section
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

//设置section的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

//设置每个cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //设置tableview的背景颜色为白色
    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]
				 initWithStyle:UITableViewCellStyleDefault
				 reuseIdentifier:SimpleTableIdentifier];
        //设置cell的背景颜色为白色
        [cell setBackgroundColor:[UIColor whiteColor]];
    }
    NSString *cellText;
    cellText=[array objectAtIndex:indexPath.row];
    cell.textLabel.text = cellText;
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    [cell setSelectionStyle:UITableViewCellSelectionStyleGray];
    return cell;
}
//cell的点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSURL *system_sound_url=[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"1248" ofType:@"wav"]];
    SystemSoundID system_sound_id;
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)system_sound_url, &system_sound_id);
    AudioServicesPlaySystemSound(system_sound_id);
    
    if(indexPath.row==0){
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://weibo.cn/waimairuanjian"]];
    }
    //tableview的cell单元格取消高亮
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
}

- (void)viewDidUnload {
    self.aboutOusTableView=nil;
    self.array=nil;
    [super viewDidUnload];
}

@end
